/* SPDX-License-Identifier: GPL-2.0 */
/*
 * VPMEM Virtual page definition
 *
 * Copyright (C) 2022 HUAWEI, Inc.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#ifndef _VPMEM_PAGE_H
#define _VPMEM_PAGE_H

#define VPAGE_MAX_ZONE 64
#define VPAGE_SHIFT	12
#define VPAGE_SIZE	(_AC(1, UL) << VPAGE_SHIFT)
#define VPAGE_MASK	(~(VPAGE_SIZE-1))

struct vpage {
	u32 zone;
	u32 units;
	struct list_head lru;
	void *freelist;
};

typedef struct vpage __iomem *vpage_ptr;

int vpage_init_zone(u64 start, u64 size, u32 nid, int force);
vpage_ptr vpage_alloc(u32 nid, gfp_t gfp_mask, unsigned int order);
void vpage_release(vpage_ptr page);
void vpage_free(const void *b, int order);
vpage_ptr virt_to_vpage(const void *addr);
vpage_ptr phys_to_vpage(unsigned long addr);

void *vpage_to_virt(vpage_ptr page);
void *vpage_phys_to_virt(unsigned long addr);
unsigned long vpage_virt_to_phys(volatile void *addr);

#endif /* _VPMEM_PAGE_H */
